﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Mapping;
using Konekcija.Core.Reporting.Dto.Application.Configurations;

namespace Konekcija.Core.Reporting.Mappings.Configurations
{
    public class NavigationMap : ClassMap<Navigation>
    {
        public NavigationMap()
        {
            Schema("config");
            Table("Navigations");

            Id(x => x.Id).GeneratedBy.GuidComb().Not.Nullable();
            Map(x => x.ParentCategoryId).Nullable();
            Map(x => x.Path).Nullable();
            Map(x => x.NavigationSetId).Column("NavigationSetId")
                .Not.Insert().Not.Update().Nullable();
            Map(x => x.Importance).Nullable();
            Map(x => x.ImageUrl).Nullable();
            Map(x => x.Url).Nullable();
            Map(x => x.DateCreated).Nullable();

            References(x => x.NavigationSet).Nullable();

            HasMany(x => x.NavigationLanguages)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Key(k => k.Not.Nullable())
                .KeyColumn("NavigationId")
                .Cascade.AllDeleteOrphan();

            HasManyToMany(x => x.Items)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Cascade.None()
                .ParentKeyColumn("NavigationId")
                .ChildKeyColumn("ItemId")
                .Table("content.ItemsToNavigations");
        }
    }
}
